package Client;
import lib.Personne;
import lib.PersonneObject;

import org.omg.CORBA.ORB;
import org.omg.CORBA.Object;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContext;
import org.omg.CosNaming.NamingContextHelper;

import M2Naming.NameCoponent;

public class ClientCreateContexte {
	
	
	 static M2Naming.NamingContext namingImpl;
	    
	 public static void main(String args[])
	 {
	  try{
	   // create and initialize the ORB
	   ORB orb = ORB.init(args, null);
		
	   // get the root naming context
	   org.omg.CORBA.Object objRef = 
	     orb.resolve_initial_references("NameService");
	   
	   // ask naming
	   NamingContext ncRef = 
	       NamingContextHelper.narrow(objRef);
	   
	   // resolve the Object Reference in Naming
	   NameComponent nc = 
	     new NameComponent("naming","");
	   NameComponent path[] = {nc};
	   
	   org.omg.CORBA.Object obj =ncRef.resolve(path);
	   namingImpl = M2Naming.NamingContextHelper.narrow(obj);
	   M2Naming.NameCoponent ncf = new M2Naming.NameCoponent("uid=chen","");
	   NameCoponent path1[] = {ncf};
	   
	   namingImpl.bind(path1,(Object) new PersonneObject());
	   System.out.println("resussir");
	   
	  } catch (Exception e) {
	      System.out.println("ERROR : " + e) ;
	      e.printStackTrace(System.out);
	  }
	 }
	
}
